package com.hy.usercenter.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;

/**
 * @Description
 * @Author minsf
 * @Date 2023/2/22
 */
@Configuration
public class RedisTemplateConfig {

    /**
     * 自定义序列化器
     *
     * @return
     */
    @Bean
    public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
        RedisTemplate<String, Object> objectObjectRedisTemplate = new RedisTemplate<>();

        objectObjectRedisTemplate.setConnectionFactory(redisConnectionFactory);

        objectObjectRedisTemplate.setKeySerializer(RedisSerializer.string());
        objectObjectRedisTemplate.setValueSerializer(RedisSerializer.json());
        return objectObjectRedisTemplate;
    }
}
